package com.enterprise.controller.api.team;

import com.alibaba.fastjson.JSON;
import com.enterprise.controller.api.common.BaseResponse;
import com.enterprise.controller.api.team.vo.TeamResp;
import com.enterprise.entity.Team;
import com.enterprise.service.TeamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;


@Slf4j
@RequestMapping("/api/team")
@Controller("TeamController")
public class TeamController {

    @Autowired
    private TeamService  teamService;

    @ResponseBody
    @RequestMapping("/queryTeamList")
    public BaseResponse<List<TeamResp>> queryCarList(){
        BaseResponse response = new BaseResponse();
        List<Team> teamList = teamService.selectList(new Team());
        List<TeamResp> teamResps = new ArrayList<>();
        for (Team team:teamList) {
            TeamResp teamResp = new TeamResp();
            BeanUtils.copyProperties(team,teamResp);
            teamResp.setStaffimgurl(BaseResponse.httpstr(teamResp.getStaffimgurl()));
            teamResps.add(teamResp);
        }
        log.info("queryTeamList teamResps: {}" , JSON.toJSONString(teamResps));
        response.setData(teamResps);
        return response;
    }


    @ResponseBody
    @RequestMapping("/queryTeamView/{id}")
    public BaseResponse<TeamResp> queryNewsView(@PathVariable("id") String id){
        BaseResponse response = new BaseResponse();
        Team team = teamService.selectById(Integer.valueOf(id));
        TeamResp teamResp = new TeamResp();
        BeanUtils.copyProperties(team,teamResp);
        teamResp.setStaffimgurl(BaseResponse.httpstr(teamResp.getStaffimgurl()));
        log.info("queryTeamView teamResp: {}" , JSON.toJSONString(teamResp));
        response.setData(teamResp);
        return response;
    }


}
